import { defineStore } from 'pinia'

// 定义鞋子设计类型
interface ShoeDesign {
  id: number;
  name: string;
  color: string;
  size: number;
}

// 定义一个存储用于管理鞋子设计相关状态
export const useShoeStore = defineStore('shoe', {
  // 状态
  state: () => ({
    designs: [] as ShoeDesign[],
    currentDesignId: null as number | null,
  }),
  
  // getter
  getters: {
    currentDesign: (state) => {
      if (state.currentDesignId === null) return null
      return state.designs.find((d: ShoeDesign) => d.id === state.currentDesignId) || null
    },
    designCount: (state) => state.designs.length,
  },
  
  // action
  actions: {
    addDesign(design: { name: string; color: string; size: number }) {
      const id = Date.now()
      this.designs.push({ ...design, id })
      return id
    },
    
    removeDesign(id: number) {
      const index = this.designs.findIndex((d: ShoeDesign) => d.id === id)
      if (index > -1) {
        this.designs.splice(index, 1)
        if (this.currentDesignId === id) {
          this.currentDesignId = null
        }
      }
    },
    
    setCurrentDesign(id: number) {
      this.currentDesignId = id
    }
  }
}) 